package edu.fight.controller;

import com.alibaba.fastjson.JSONObject;
import edu.fight.dto.JwtUser;
import edu.fight.dto.Result;
import edu.fight.dto.ResultStatus;
import edu.fight.entity.User;
import edu.fight.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

@RestController
@RequestMapping("/auth")
@Slf4j
public class LoginController {

    @Autowired
    UserService userService;

    @PostMapping("/login")
    public Result login(User user){
        try {
            String token = userService.login(user);
            return Result.to(ResultStatus.sucess,"",null,token);
        }catch (Exception e){
            e.printStackTrace();
            return Result.to(ResultStatus.error,e.getMessage(),null,null);
        }
    }

}
